<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page import="java.sql.*" %>
<%@ page import="javax.sql.rowset.WebRowSet" %>  
<!DOCTYPE html>  
<html>  
<head>  
    <meta charset="UTF-8">  
    <title>用户预定表</title>  
    <style>
  .hotel-search body{
       
        
        background-color: #f2f2f2; 
        font-family: Arial, sans-serif;  
        margin: 0;  
        padding: 0;  }
  
    .hotel-search{  
        max-width: 800px;  
        margin: 20px auto;  
        background-color: #fff;   
        padding: 20px;  
        box-shadow: 0 0 10px rgba(0,0,0,0.1);  
    }  
   .hotel-search h2 {  
        color: #ffa500; 
        text-align: center;  
    }  
   .hotel-search table {  
        width: 100%;  
        border-collapse: collapse;  
        margin-top: 20px;  
    }  
   .hotel-search th, td {  
        padding: 8px;  
        text-align: left;  
        border-bottom: 1px solid #ddd;  
    }  
   .hotel-search th {  
        background-color: #ffa500; 
        color: #fff;  
    }  
   .hotel-search form {  
        margin-top: 20px;  
    }  
    .hotel-search input[type=text], input[type=submit] {  
        padding: 5px 10px;  
        font-size: 16px;  
    }  
   .hotel-search  input[type=submit] {  
        background-color: #ffa500;  
        color: #fff;  
        border: none;  
        cursor: pointer;  
    }  
</style>

</head>  
<body>  
    <div class="hotel-search">  
        <h2>session数据</h2>  
        <%  
        String id = (String)session.getAttribute("id");  
        out.println("<br>管理者: " + session.getAttribute("account"));  
        %> 
         
       <h2>用户登录入住</h2>
       <a href="user_check_in.jsp">分配房间</a> 
       
       <h2>用户退房结算</h2>
       <a href="user_check_out.jsp">退还房间</a> 
     
        <h2>所有用户列表</h2>  
        
            <table width="100%" border="1">
    <tr>
       <th>userid</th>
        <th>name</th>
        <th>phone</th>
        <th>roomtype</th>
        <th>indate</th>
        <th>outdate</th>
         <th>amount</th>
         <th>price</th>
         <th>room_number</th>
        <th width="10%">操作</th>
    </tr>
    
   
        <%
        javax.sql.rowset.WebRowSet rs1 = aa.db.DBTools.getRS("SELECT * FROM 成都梦之旅文君楼庭院酒店（宽窄巷子店）");
        
        
            while(rs1.next()){
            	%>
            
        <tr onclick="fillform(this)" style="cursor:pointer">
         <td><%=rs1.getString("userid")%></td>
            <td><%=rs1.getString("name")%></td>
            <td><%=rs1.getString("phone")%></td>
            <td><%=rs1.getString("roomType")%></td> 
            <td><%=rs1.getString("indate")%></td>
            <td><%=rs1.getString("outdate")%></td>
            <td><%=rs1.getString("amount")%></td> 
            <td><%=rs1.getString("price")%></td>
            <td><%=rs1.getString("room_number")%></td>
           
            <td>
                <a href="edit1.jsp?id=<%=rs1.getString("userid")%>">修改</a>
            <a href="save1.jsp?btn=del&userid=<%=rs1.getString("userid")%>" class="button-delete" onclick="return confirm('请确认是否删除当前记录？');">删除</a>  
              
             </td>
        </tr>
        <%
            }
            rs1.close();
        %>
    
        </table>  </div>
      <div class="hotel-search">    
 <h1>空置房间列表</h1>
<%
    try {
        // 加载JDBC驱动
        Class.forName("org.mariadb.jdbc.Driver");

        // 数据库连接信息
        String dbURL = "jdbc:mariadb://10.220.140.102:3366/studb11";
        String username = "stua";
        String password = "zHZUA65r";

        // 建立连接
        Connection conn = DriverManager.getConnection(dbURL, username, password);

        // 查询空置房间
        String sql = "SELECT room_number, name, indate, outdate FROM 成都梦之旅文君楼庭院酒店（宽窄巷子店） WHERE status = '空置'";
        Statement stmt = conn.createStatement();
        ResultSet rs2 = stmt.executeQuery(sql); 
%>
<table border="1">
    <tr>
        <th>房间号</th>
        <th>名称</th>
        <th>入住日期</th>
        <th>离店日期</th>
    </tr>
    <%
        while (rs2.next()) {
    %>
    <tr>
         <td><%= rs2.getString("room_number") %></td>
        <td><%= rs2.getString("name") %></td>
        <td><%= rs2.getString("indate") %></td>
        <td><%= rs2.getString("outdate") %></td>
    </tr>
    <%
        }
    %>
</table>
<%
        
         rs2.close();
         stmt.close();
         conn.close();
    } catch (Exception e) {
        e.printStackTrace(); 
    }
%>
 </div>
 
        <hr>
   <div class="hotel-search"> 
        <h2>新增用户</h2>
   <form action="save1.jsp"method="post">
     <label for="userid">userid:</label>
     <input type="text" id="userid" name="userid" required><br><br>
     <label for="name">name:</label>
     <input type="text" id="uname" name="name" required><br><br>
     <label for="phone">phone:</label>
     <input type="text" id="phone" name="phone" required><br><br>
     <label for="roomType">roomType:</label>
     <select id="roomType" value="1">
             <option value="1">单人间</option>
             <option value="2">双人间</option>
             <option value="3">大床房</option>
             <option value="4">钟点房</option>
         </select>  
         <br><br>
     <label for="indate">indate:</label>
     <input type="datetime-local" id="indate" name="indate" required><br> <br> 
     <label for="outdate">outdate:</label>
     <input type="datetime-local" id="outdate" name="outdate" required><br><br>
     <label for="amount">amount:</label>
     <input type="text" id="amount" name="amount" required><br><br>
     <label for="price">price:</label>
     <input type="text" id="price" name="price" required><br><br>
     <label for="roomnumber">room_number:</label>
     <input type="text" id="room_number" name="room_number" required><br><br>
     
     <input type="submit" name="btn" value="提交" ><br><br>
</form>

<h2>发布房源信息</h2>
<form action="submit_room.jsp" method="post">
    <label for="roomType">房型:</label>
    <input type="text" id="roomType" name="roomType" required><br><br>
    
    <label for="price">价格:</label>
    <input type="number" id="price" name="price" required><br><br>
    
    <label for="description">描述:</label>
    <textarea id="description" name="description" required></textarea><br><br>
    
    <input type="submit" value="发布">
</form>
</div>

     <script>
        function fillform(row) {
        	console.info(row);
        	var tds = row.getElementsByTagName("td");
        	
        	//填入表单
        	userid.value=tds[0].innerText;
        	uname.value=tds[1].innerText;
        	phone.value=tds[2].innerText;
        	roomType.value=tds[3].innerText;
        	indate.value=tds[4].innerText;
        	outdate.value=tds[5].innerText;
        	amount.value=tds[6].innerText;
        	price.value=tds[7].innerText;
        	room_number.value=tds[8].innerText;
        }        	      
    </script>
</body>
</html>

